from django.db import models
from article.models import ArticleModel


# Create your models here.
class ADModel(models.Model):
    """
    主页广告
    """
    ad_name = models.CharField(max_length=100, default='', null=False, blank=False, verbose_name='广告标题')
    ad_link = models.CharField(max_length=200, default='', null=False, blank=False, verbose_name='广告链接')
    ad_image = models.ImageField(max_length=200, upload_to="ad/", verbose_name='广告图片')
    ad_order = models.IntegerField(default=0, verbose_name='广告排序')
    due_time = models.DateTimeField(null=False, verbose_name='过期时间')
    create_at = models.DateTimeField(auto_now_add=True, null=False, verbose_name='添加时间')
    update_at = models.DateTimeField(auto_now=True, null=False, verbose_name='修改时间')

    class Meta(object):
        verbose_name = '主页广告'
        verbose_name_plural = verbose_name


class DetailAdModel(models.Model):
    """
    文章详情页面广告
    """
    ad_name = models.CharField(max_length=100, default='', null=False, blank=False, verbose_name='广告标题')
    ad_link = models.CharField(max_length=200, default='', null=False, blank=False, verbose_name='广告链接')
    ad_image = models.ImageField(max_length=200, upload_to="ad/", verbose_name='广告图片')
    ad_order = models.IntegerField(default=0, verbose_name='广告排序')
    due_time = models.DateTimeField(null=False, verbose_name='过期时间')
    article = models.ForeignKey(ArticleModel, on_delete=models.CASCADE, verbose_name='关联文章')
    create_at = models.DateTimeField(auto_now_add=True, null=False, verbose_name='添加时间')
    update_at = models.DateTimeField(auto_now=True, null=False, verbose_name='修改时间')

    class Meta(object):
        verbose_name = '文章广告'
        verbose_name_plural = verbose_name
